<?php

require 'db.php';

$strsql = "select * from shopping ";
if(isset($_GET['search'])){
    $strsql  .= " where Price like '%".$_GET['search']."%'"; //模糊匹配
}

$current_order = "";



    if (isset($_GET['order_one'])){
        $current_order= $_GET['order_one'];
            $strsql .= " order by shopping.ProductName ".$current_order;  
    }
    elseif (isset($_GET['order_two'])){
        $current_order = $_GET['order_two'];
        $strsql .= " order by shopping.Model ".$current_order;
    }
    elseif (isset($_GET['order_three'])){
        $current_order = $_GET['order_three'];
        $strsql .= " order by shopping.Price ".$current_order;
    }
    elseif (isset($_GET['order_four'])){
        $current_order = $_GET['order_four'];
        $strsql .= " order by shopping.Quantity ".$current_order;
    }
    elseif (isset($_GET['order_five'])){
        $current_order = $_GET['order_five'];
        $strsql .= " order by shopping.Status ".$current_order;
    }  
$order_t=($current_order == "desc") ? "asc" : "desc";


$result = mysqli_query($link, $strsql);
$data = mysqli_fetch_all($result);

mysqli_free_result($result);
mysqli_close($link);


$per_page = 10;//每页显示的条数
$total_num = count($data);//总条数
$total_page = ceil($total_num / $per_page);//向上取整

$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;//获取当前页码
//页码合理性判断的第二种方式，两种方式任选其一即可

$page = max($page,1);
$page = min($page,$total_page);

//页码合理性判断的第二种方式，任选其一即可
$pre_page = ($page - 1) < 1 ? $page : ($page-1);
$next_page =($page + 1) > $total_page ? $page : ($page+1);
// $pre_page = $page - 1;
// $next_page =$page + 1;
$page_1=$page+1;
$page_2=$page+2;
$page_3=$page+3;

$end_index = $per_page*$page - 1;
$end_index = min($end_index,$total_num - 1);

$start_index = ($per_page*($page - 1)-1)+1;

require 'index.html';
?>